layui.use(['form', 'layedit', 'laydate','element','table','jquery'], function () {
	var form = layui.form
	,layer = layui.layer
	,layedit = layui.layedit
	,laydate = layui.laydate
	,element = layui.element
	,$ = layui.$ //引入jquery
	,table = layui.table;
	$('input[name="zhuce"]').click(function () {
		layer.open({
			type: 1,
			title:'注册账号',
			skin: 'layui-layer-molv', //样式类名
			closeBtn: 0, //不显示关闭按钮
			anim: 2,
			id:'zhuceForm',
			shadeClose: true, //开启遮罩关闭
			content: `<div style="padding: 20px; line-height: 22px; background-color: #eee; color: #000; font-weight: 300;">
				<form class="layui-form" action="" >
				<table class="z-table">
				<tr>
				<td>账号：</td>
				<td>
				<input type="text" class="layui-input " name="username" autocomplete="off" lay-verify="required">
				</td>
				<td><img id="valid" src="" style="height:35px"></td>
				</tr>
				<tr>
				<td>密码：</td>
				<td>
				<input type="password" class="layui-input" name="password" placeholder="请输入6到12位密码" autocomplete="off" lay-verify="password">
				</td>
				</tr>
				<tr>
				<td>确认密码：</td>
				<td> 
				<input type="password" class="layui-input" name="password2" placeholder="请重复输入密码" autocomplete="off" lay-verify="confirm">
				</td>
				</tr>
				<tr>
				<td>
				地址
				</td>
				<td>
					<select name="province"></select>
				</td>
				<td>
					<select name="city"></select>
				</td>
				<td>
					<select name="area"></select>
				</td>
				</tr>
				<tr>
				<td>电话：</td>
				<td>
				<input type="text" class="layui-input" name="iphone" autocomplete="off" lay-verify="phone">
				</td>
				</tr>
				<tr>
				<td>邮箱：</td>
				<td>
				<input type="text" class="layui-input" name="email" autocomplete="off" lay-verify="email">
				</td>
				</tr>
				</table>
				<div class="layui-form-item" style="padding:10px 0px;">
				<a type="button" style="float:right;margin:10px;" class="layui-btn" lay-submit lay-filter="tijiao">立即提交</a>
				</div>
				<form>
				</div>`
				,success:function(layero){
					new PCAS("province","city","area");
					form.render('select');
					$("input[name='username']").blur(function(){
						$.get('user/validUserName',{username:$('input[name="username"]').val()},function(data,status){
							if(data.result){
								$('#valid').attr("src","img/ok.png");
							}else{
								$('#valid').attr("src","img/cancel.png");
							}
						})
					})
				}
		});
	})

	form.verify({
		username: function(value, item){ //value：表单的值、item：表单的DOM对象
			if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
				return '用户名不能有特殊字符';
			}
			if(/(^\_)|(\__)|(\_+$)/.test(value)){
				return '用户名首尾不能出现下划线\'_\'';
			}
			if(/^\d+\d+\d$/.test(value)){
				return '用户名不能全为数字';
			}
		}
		//我们既支持上述函数式的方式，也支持下述数组的形式
		//数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
	,password: [
		/^[\S]{6,12}$/
		,'密码必须6到12位，且不能出现空格'
		] ,
	confirm:function(value){
		       if(value!=$('input[name="password"]').val()){
		        return '两次输入的密码不一致！';
		       }
		  }
	});
	form.on('submit(tijiao)',function(data){
		var content = data.field;
		console.info(content);
		
	})
	/* var msgalert = '默认账号:' + testcount + '<br/> 默认密码:' + testpassword;
    		var index = layer.alert(msgalert, { icon: 6, time: 4000, offset: 't', closeBtn: 0, title: '友情提示', btn: [], anim: 2, shade: 0 });  
			layer.style(index, {
				color: '#777'
			}); */ 
	//非空验证
	$('input[name="login"]').click(function () {
		var login = $('input[name="login"]').val();
		var pwd = $('input[name="pwd"]').val();
		var code = $('input[name="code"]').val();
		if (login == '') {
			ErroAlert('请输入您的账号');
		} else if (pwd == '') {
			ErroAlert('请输入密码');
		} else if (code == '' || code.length != 4) {
			ErroAlert('输入验证码');
		} else {
			//认证中..
			/* fullscreen(); */
			$('.login').addClass('test'); //倾斜特效
			setTimeout(function () {
				$('.login').addClass('testtwo'); //平移特效
			}, 300);
			setTimeout(function () {
				$('.authent').show().animate({ right: -320 }, {
					easing: 'easeOutQuint',
					duration: 600,
					queue: false
				});
				$('.authent').animate({ opacity: 1 }, {
					duration: 200,
					queue: false
				}).addClass('visible');
			}, 500);

			//登陆
			var JsonData = { login: login, pwd: pwd, code: code };
			//此处做为ajax内部判断
			var url = "";
			if(JsonData.login == truelogin && JsonData.pwd == truepwd && JsonData.code.toUpperCase() == CodeVal.toUpperCase()){
				url = "Ajax/Login";
			}else{
				url = "Ajax/LoginFalse";
			}


			AjaxPost(url, JsonData,
					function () {
				//ajax加载中
			},
			function (data) {
				//ajax返回 
				//认证完成
				setTimeout(function () {
					$('.authent').show().animate({ right: 90 }, {
						easing: 'easeOutQuint',
						duration: 600,
						queue: false
					});
					$('.authent').animate({ opacity: 0 }, {
						duration: 200,
						queue: false
					}).addClass('visible');
					$('.login').removeClass('testtwo'); //平移特效
				}, 2000);
				setTimeout(function () {
					$('.authent').hide();
					$('.login').removeClass('test');
					if (data.Status == 'ok') {
						//登录成功
						$('.login div').fadeOut(100);
						$('.success').fadeIn(1000);
						$('.success').html(data.Text);
						//跳转操作

					} else {
						AjaxErro(data);
					}
				}, 2400);
			})
		}
	})
	
})

